package com.qf.controller;

import com.qf.dto.R;
import com.qf.entity.SysScene;
import com.qf.entity.SysUserInfo;
import com.qf.pojo.BaseUser;
import com.qf.service.SceneService;
import com.qf.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @Author ztf
 * @Date 21:50 2022/1/2
 * 场景接口
 **/
@RestController
@RequestMapping("scene")
public class SceneController {
    private SceneService sceneService;

    @Autowired
    public void setSceneService(SceneService sceneService) {
        this.sceneService = sceneService;
    }

    @PostMapping("addscene")
    public R addScene(@RequestBody SysScene scene) {
        sceneService.addScene(scene);
        return R.setOK();
    }

    @PostMapping("updatescene")
    public R updateScene(@RequestBody SysScene scene) {
        sceneService.updateScene(scene);
        return R.setOK();
    }

    @DeleteMapping("deletescene")
    public R deleteScene(@RequestBody List<Long> sceneIds) {
        sceneService.deleteSceneById(sceneIds);
        return R.setOK();
    }

    @GetMapping("scenes")
    public R findAllSceneByUser() {
        BaseUser user = SecurityUtils.getUser();
        List<SysScene> scenes = null;
        try {
            scenes = sceneService.findByUserId(user.getUserId());
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return R.setOK(scenes);
    }
}
